package com.jr.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result implements Serializable {

    private int code; //状态码
    private String mes; //状态信息
    private Object data; //返回的响应数据

    public static Result success(Object data){
        return success(200,"操作成功！",data);
    }
    public static Result success(){
        return success(200,"操作成功！",null);
    }

    private static Result success(int code, String mes, Object data) {
        Result result=new Result();
        result.setCode(code);
        result.setMes(mes);
        result.setData(data);
        return result;
    }
    public static Result fail(String mes){
        return fail(400,mes,null);
    }

    private static Result fail(int code, String mes, Object data) {
        Result result=new Result();
        result.setCode(code);
        result.setMes(mes);
        result.setData(data);
        return result;
    }

}
